package com.chinasofti.mydate.myjdk8datetime;

import java.text.ParseException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;

//时间类的添加和减少时间
public class JKD8DateDemo8 {
    public static void main(String[] args) throws ParseException {
        LocalDate localDate = LocalDate.of(2020, 1, 1);
        LocalDate localDate2 = LocalDate.of(2040, 12, 12);
        Period period=Period.between(localDate, localDate2);
        System.out.println("period="+period);//period=P20Y11M11D

        System.out.println(period.getYears());//这期间的年数
        System.out.println(period.getMonths());//这期间的月数
        System.out.println(period.getDays());//这期间的天数

        System.out.println(period.toTotalMonths());//获取期间总月数


    }


}